package designPatterns.P05_适配器模式_Adapter.P01_类适配器_ClassAdapter.adaptors;

import designPatterns.P05_适配器模式_Adapter.P01_类适配器_ClassAdapter.voltages.Voltage;
import designPatterns.P05_适配器模式_Adapter.P01_类适配器_ClassAdapter.voltages.Voltage220V;

import java.util.Objects;

/**
 * @author d11yu
 */
public class Adaptor220VTo5V extends Voltage220V implements Adaptor {

    @Override
    public Voltage convert(Voltage vol220) throws CloneNotSupportedException, VoltageValueErrorException {
        if (Objects.equals(vol220.getV(), getInputVoltage())) {
            Voltage clone = (Voltage) vol220.clone();
            clone.setV(5);
            return clone;
        } else {
            throw new VoltageValueErrorException("传入电压伏特数不匹配（" + getInputVoltage() + "V）！");
        }

    }

    @Override
    public Integer getInputVoltage() {
        return 220;
    }
}
